package com.thread;

public class ThreadInfoDemo {
    public static void main(String[] args) {
        Thread main = Thread.currentThread();
        System.out.println("main = " + main);
        showInfo();

        //创建新的线程, 并启动
        new Thread(() -> showInfo()).start();
    }

    public static void showInfo() {
        Thread t = Thread.currentThread();
        System.out.println("t = " + t);

        //获取线程的名称
        String name = t.getName();
        System.out.println("线程的名称 = " + name);

        //获取线程的id
        long id = t.getId();
        System.out.println("线程的id = " + id);

        //获取线程的优先级
        int priority = t.getPriority();
        System.out.println("线程的优先级 = " + priority);

        //获取线程是否是守护线程
        boolean daemon = t.isDaemon();
        System.out.println("线程是否是守护线程 = " + daemon);

        //获取线程是否存活
        boolean alive = t.isAlive();
        System.out.println("线程是否存活 = " + alive);

        //获取线程是否中断
        boolean interrupted = t.isInterrupted();
        System.out.println("线程是否中断 = " + interrupted);
    }
}
